import Data.Char
isCurious x
          | sumFacs x == x = True
          | otherwise = False

facs = scanl (*) 1 [1..]
fac n = facs !! n

sumFacs x = sumFacs' $ show x
sumFacs' :: String -> Integer
sumFacs' [] = 0
sumFacs' (x:xs) = fac (digitToInt x) + sumFacs' xs

main = [x | x<-[3..7*fac 9], isCurious x]